# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 15:24
# @Author  : lt
# @Email   : lt@163.com
# @File    : sj_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from page.KHGL_page.Base_Page import BasePage
from selenium.webdriver.support.select import Select
class Sj_Page(BasePage):
    # 定位添加商机按钮
    addshangji_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > div > a')
    # 定位删除按钮
    delete_locator = (By.ID, 'delete')
    # 定位回收站商机的表
    shangji_tobdy_locator = (By.XPATH, '//*[@id="form1"]/table/tbody')
    # 定位商机tobdy
    tobdy_sj_locator = (By.CSS_SELECTOR, '#form1 > table > tbody')
    # 定位商机回收站
    huishouzhan_locator = (By.LINK_TEXT, '回收站')
    # 定位前进阶段下拉框
    jieduan_locator = (By.NAME, 'status_id')
    # 定位下次联系时间
    next_time_locator = (By.ID, 'nextstep_time')
    # 定位下次联系内容
    next_stap_locator = (By.ID, 'nextstep')
    # 定位描述输入框
    description_locator = (
    By.CSS_SELECTOR, '#dialog-advance > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > textarea')
    # 定位推进按钮
    tuijin_button_locator = (By.CSS_SELECTOR, '#dialog-advance > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > input.btn.btn-primary')


    #点击新建商机
    def add_sjj(self):
        self.driver.find_element(*self.addshangji_locator).click()
    # 选则要删除的商机
    def shangji_delete(self,shangji_name):
        tobdy_sj = self.driver.find_element(*self.tobdy_sj_locator)
        trs = tobdy_sj.find_elements(By.TAG_NAME, 'tr')
        for tr in trs:
            tds = tr.find_elements(By.TAG_NAME, 'td')
            if tds[3].text == shangji_name:
                print(tds[3].text)
                tds[0].find_element(By.CSS_SELECTOR, 'input[name="business_id[]"]').click()
    # 点击删除
    def delete_click(self):
        self.driver.find_element(*self.delete_locator).click()
        self.driver.switch_to.alert.accept()
    # 点击回收站
    def huishouzhan_click(self):
        self.driver.find_element(*self.huishouzhan_locator).click()
    #选择要清空的商机
    def qingkong(self,shangji):
        shangji_tobdy = self.driver.find_element(*self.shangji_tobdy_locator)
        trs1 = shangji_tobdy.find_elements(By.TAG_NAME, 'tr')
        for e in trs1:
            tds1 = e.find_elements(By.TAG_NAME, 'td')
            if tds1[3].text == shangji:
                tds1[0].find_element(By.CSS_SELECTOR, 'input[name="business_id[]"]').click()
    # 点击删除回收站
    def delete_huishou(self):
        self.driver.find_element(*self.delete_locator).click()
        self.driver.switch_to.alert.accept()

    # 选择要推进的商机
    def xuanze_shangji(self,sahngji_name):
        tobdy_sj = self.driver.find_element(*self.tobdy_sj_locator)
        trs = tobdy_sj.find_elements(By.TAG_NAME, 'tr')
        for tr in trs:
            tds = tr.find_elements(By.TAG_NAME, 'td')
            if tds[3].text == sahngji_name:
            # 点击推进按钮
                tds[11].find_element(By.LINK_TEXT, '推进').click()
    # 选择要推进到的阶段
    def jiesuan_shuru(self,jieduan):
        Select(self.driver.find_element(*self.jieduan_locator)).select_by_visible_text(jieduan)
    # 输入下次联系时间
    def next_time_shuru(self, next_time):
        self.driver.find_element(*self.next_time_locator).send_keys(next_time)
    # 输入下次联系内容
    def next_step_shuru(self,next_step):
        self.driver.find_element(*self.next_stap_locator).send_keys(next_step)
    # 输入描述信息
    def description_shuru(self, description):
        self.driver.find_element(*self.description_locator).send_keys(description)
    # 点击推进
    def tuijin_click(self):
        self.driver.find_element(*self.tuijin_button_locator).click()
    # 断言
    def tianjia_succeful(self):
     text = self.driver.find_element(By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success').text
     return text
